package week10;

import java.text.NumberFormat;

public class PP13_1 {
    public static void main(String[] args) {
        DVDList dvdList = new DVDList();
        dvdList.add(new DVD("The Godfather", "Francis Ford Coppla", 1972, 24.95, true));
        dvdList.add(new DVD("District 9", "Neill Blomkamp", 2009, 19.95, false));
        dvdList.add(new DVD("Iron Man", "Jon Favreau", 2008, 15.95, false));
        dvdList.add(new DVD("All About Eve","Joseph Mankiewicz", 1950, 17.50, false));
        dvdList.add(new DVD("The Matrix", "Andy & Lana Wachowski", 1999, 19.95, true));
        System.out.println(dvdList);

        dvdList.add(new DVD("Iron Man 2", "Jon Favreau", 2010, 22.99, false));
        dvdList.add(new DVD("Casablanca", "Michael Curtiz", 1942, 19.95, false));

        System.out.println(dvdList);
    }
}

class DVD
{
    private String title, director;
    private int year;
    private double cost;
    private boolean bluray;

    //------------------------------------------------------------------------
    //  Creats a new DVD with the specified information.
    //------------------------------------------------------------------------
    public DVD(String title, String director, int year, double cost, boolean bluray)
    {
        this.title = title;
        this.director = director;
        this.year = year;
        this.cost = cost;
        this.bluray = bluray;
    }

    //-------------------------------------------------------------------------
    //  Returns a string description of this DVD.
    //-------------------------------------------------------------------------
    @Override
    public String toString()
    {
        NumberFormat fmt = NumberFormat.getPercentInstance();
        String description;

        description = fmt.format(cost) + "\t" + year + "\t";
        description += title + "\t" + director;
        if (bluray) {
            description += "\t" + "Blu-ray";
        }

        return description;
    }
}

class DVDList{
    private DVDNode list;
    public DVDList(){list = null;}
    public void add(DVD d) {
        DVDNode node = new DVDNode(d);
        DVDNode current;
        if (list == null) {
            list = node;
        } else {
            current = list;
            while (current.next != null) {
                current = current.next;
            }
                current.next = node;

        }
    }
    @Override
    public String toString(){
       String result = "";
       DVDNode current = list;
       while (current!=null){
           result+=current.dvd + "\n";
           current=current.next;
       }
       return result;
    }

}

class DVDNode{
    public DVD dvd;
    public DVDNode next;
    public DVDNode(DVD d){
        dvd = d;
        next = null;
    }

    public DVD getDvd() {
        return dvd;
    }
}